<?php
namespace Versal\AdminBundle\Common\Util;

use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;

 class ObjectSerializer{
    
    private $serializer;
    
    function __construct(){
        $encoders = array(new XmlEncoder(), new JsonEncoder());
	   	$normalizers = array(new GetSetMethodNormalizer());
        $this->serializer = new Serializer($normalizers, $encoders);
    }
    
    public function serializeJson($objeto){
          
          return $this->serializer->serialize($objeto, 'json');
    }
    
    public function serializeXml($objeto){
          
          return $this->serializer->serialize($objeto, 'xml');
    }
    
}